// https : // iai.sh.cn/problem/530
#include <bits/stdc++.h>
using namespace std;
int dp[1000001];
int main() {
  string s;
  cin >> s;
  int n = s.size();
  int total = 0;
  dp[0] = (s[0] - '0') % 3; // 初始化 dp[0]
  for (int i = 1; i < n; i++) { // 从 1 开始循环
    dp[i] = dp[i - 1] + s[i] - '0';
    dp[i] %= 3;
  }
  long long int a = 0, b = 0, c = 0;
  for (int i = 0; i < n; i++) {
    if (dp[i] == 0) {
      a++;
    } else if (dp[i] == 1) {
      b++;
    } else if (dp[i] == 2) {
      c++;
    }
  }

  cout << a * (a + 1) / 2 + b * (b - 1) / 2 + c * (c - 1) / 2 << endl;
  return 0;
}